package com.example.service;

import com.example.entity.Options;
import com.example.entity.PostCategory;
import com.example.mapper.PostCategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
帖子分类业务处理
 */
@Service
public class PostCategoryService {

    @Resource
    private PostCategoryMapper postCategoryMapper;

    public void add(PostCategory postCategory) {
        postCategoryMapper.insert(postCategory);
    }

    public void deleteById(Integer id) {
        postCategoryMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(PostCategory postCategory) {
        postCategoryMapper.updateById(postCategory);
    }

    public PostCategory selectById(Integer id) {
        return postCategoryMapper.selectById(id);
    }

    public List<PostCategory> selectAll(PostCategory postCategory) {
        return postCategoryMapper.selectAll(postCategory);
    }

    public PageInfo<PostCategory> selectPage(PostCategory postCategory, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PostCategory> postCategoryList = postCategoryMapper.selectAll(postCategory);
        return PageInfo.of(postCategoryList);
    }
}
